package com.liangzi.service_core.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.liangzi.liangzi_common.result.R;
import com.liangzi.service_core.pojo.entity.InnerDoctor;
import com.liangzi.service_core.pojo.entity.VisitBooking;
import com.liangzi.service_core.pojo.entity.VisitBookingHistory;
import com.liangzi.service_core.pojo.entity.VisitMedicalCard;
import com.liangzi.service_core.pojo.vo.VisitBookingHistoryVO;
import com.liangzi.service_core.service.*;
import com.liangzi.servicebase.util.RedisUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.DecimalMax;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * <p>
 * 预约历史记录表 前端控制器
 * </p>
 *
 * @author zhj
 * @since 2021-12-13
 */
//@Api(description = "预约历史记录表")
@RestController
//@RequestMapping("/web/visitBookingHistory")
public class VisitBookingHistoryController {
    //@Autowired
    //private VisitBookingService visitBookingService;
    //@Autowired
    //private VisitBookingHistoryService visitBookingHistoryService;
    //@Autowired
    //private RedisUtil redisUtil;
    //@Autowired
    //private VisitMedicalCardService visitMedicalCardService;
    //@Autowired
    //private InnerDoctorService innerDoctorService;
    //
    //
    //
    //
    //
    //// 获取当前卡下的所有预约表列表
    //@ApiOperation("获取当前卡下的所有预约列表")
    //@GetMapping("getBookingHistory/{rdSession}")
    //public R getBookingHistory(@PathVariable("rdSession") String rdSession){
    //    // 判断是否登录
    //    String userId = (String) redisUtil.get("session:" + rdSession);
    //    if (userId == null) {
    //        return  R.error().message("请重新登录");
    //    }
    //
    //    // 根据userId获取获取cardId
    //    QueryWrapper<VisitMedicalCard> visitMedicalCardQueryWrapper = new QueryWrapper<>();
    //    visitMedicalCardQueryWrapper.eq("user_id",userId);
    //    VisitMedicalCard visitMedicalCard = visitMedicalCardService.getOne(visitMedicalCardQueryWrapper);
    //    // 根据cardId获取所有的预约记录
    //    QueryWrapper<VisitBookingHistory> visitBookingHistoryQueryWrapper = new QueryWrapper<>();
    //    visitBookingHistoryQueryWrapper.eq("medical_card_id",visitMedicalCard.getMedicalCardId());
    //    Collection<VisitBookingHistory> list = visitBookingHistoryService.list(visitBookingHistoryQueryWrapper);
    //    List<VisitBookingHistoryVO> visitBookingHistoryVOList = new ArrayList<>();
    //    for (VisitBookingHistory visitBookingHistory : list) {
    //        VisitBookingHistoryVO visitBookingHistoryVO = new VisitBookingHistoryVO();
    //        visitBookingHistoryVO.setBookingHistoryId(visitBookingHistory.getBookingHistoryId());
    //        String visitBookingId = visitBookingHistory.getVisitBookingId();
    //        VisitBooking visitBooking = visitBookingService.getById(visitBookingId);
    //        //booking bookingId   bookingDate bookingName bookingPhone  // innerDoctorId
    //        BeanUtils.copyProperties(visitBooking,visitBookingHistoryVO,VisitBookingHistoryVO.class);
    //        String innerDoctorId = visitBooking.getInnerDoctorId();
    //        InnerDoctor innerDoctor = innerDoctorService.getById(innerDoctorId);
    //        visitBookingHistoryVO.setDoctorName(innerDoctor.getDoctorName());
    //        visitBookingHistoryVO.setDoctorOutpatient(innerDoctor.getDoctorOutpatient());
    //        visitBookingHistoryVO.setBooking(visitBookingHistory.getBooking());
    //        visitBookingHistoryVOList.add(visitBookingHistoryVO);
    //    }
    //
    //
    //    return R.ok().data("records", visitBookingHistoryVOList);
    //}
    //
    //
    //
    //// 取消预约
    //@ApiOperation("获取当前卡下的所有预约列表")
    //@PostMapping("CancelBooking/{rdSession}/{bookingId}/{bookingHistoryId}")
    //public R CancelBooking(
    //        @PathVariable("rdSession") String rdSession,
    //        @PathVariable("bookingId") String bookingId,
    //        @PathVariable("bookingHistoryId") String bookingHistoryId
    //
    //) {
    //    // 判断是否登录
    //    String userId = (String) redisUtil.get("session:" + rdSession);
    //    if (userId == null) {
    //        return R.error().message("请重新登录");
    //    }
    //    // 106 已预约  109 已取消 TODO 添加事务
    //    // 修改预约表记录状态
    //    VisitBooking visitBooking = visitBookingService.getById(bookingId);
    //    visitBooking.setBooking(109);
    //    boolean isUpdate = visitBookingService.updateById(visitBooking);
    //    // 添加预约记录历史记录
    //    VisitBookingHistory visitBookingHistory = visitBookingHistoryService.getById(bookingHistoryId);
    //    visitBookingHistory.setBookingHistoryId("");
    //    visitBookingHistory.setBooking(109);
    //    visitBookingHistory.setRemark("取消预约");
    //    boolean isSave = visitBookingHistoryService.save(visitBookingHistory);
    //    return isUpdate && isSave ? R.ok().message("取消成功") : R.error().message("取消失败");
    //}
}

